<?PHP
	$GLOBALS['starttime'] = microtime('time');
	
	$system = "core";
	
	$application = "";
	
	define('EXT', '.php');
	
	define('DS', DIRECTORY_SEPARATOR);
	
	error_reporting(E_ALL);
	
	define('DOCROOT', realpath(dirname(__FILE__)).DS);
	
	if (is_dir($system) and is_dir(DOCROOT.$system))
	{
		$system = DOCROOT.$system;
	}
	
	if ( ! is_dir($application) and is_dir(DOCROOT.$application))
	{
		$application = DOCROOT.$application;
	}

	define('SYSPATH', $system);
	
	define('APPPATH', $application);

	define('WEBFOLDER', '/chilik-wiki/');
	
	unset($system, $application);
	
	require_once SYSPATH.DS.'chilik'.EXT;
	
	/*
	$CHILIK = array(
		'framework' => 'Chilik - Simple PHP MVC Framework',
		'default' => array(
						'controller' => 'wiki',
						'smarty_template' => TRUE,
						'database' => array(
										'driver' => 'sqlite',
										'database' => APPPATH.'sqlite'.DS.'wiki.sqlite'
									)
					)
	);
	*/
	
	$GLOBALS['framework'] = 'Chilik - Simple PHP MVC Framework';
	
	$GLOBALS['default_controller'] = 'wiki';
	
	$GLOBALS['smarty_template'] = FALSE;
	
	$GLOBALS['twig_template'] = TRUE;
	
	$GLOBALS['default_database'] = array(
		'driver' => 'sqlite',
		'database' => APPPATH.'sqlite'.DS.'wiki.sqlite'
	);
	
	//===============================================
	// Session
	//===============================================
	/*
	session_start();
	*/
	//===============================================
	// Uncaught Exception Handling
	//===============================================s
	/*
	set_exception_handler('uncaught_exception_handler');

	function uncaught_exception_handler($e) {
	  ob_end_clean(); //dump out remaining buffered text
	  $vars['message']=$e;
	  die(View::do_fetch(APP_PATH.'errors/exception_uncaught.php',$vars));
	}

	function custom_error($msg='') {
	  $vars['msg']=$msg;
	  die(View::do_fetch(APP_PATH.'errors/custom_error.php',$vars));
	}
	*/
	
	//===============================================
	// Autoloading for Business Classes
	//===============================================
	// Assumes Model Classes start with capital letters and Helpers start with lower case letters
	/*
	function __autoload($classname) {
	  $a=$classname[0];
	  if ($a >= 'A' && $a <='Z')
	    require_once(APP_PATH.'models/'.$classname.'.php');
	  else
	    require_once(APP_PATH.'helpers/'.$classname.'.php');  
	}
	*/
	
	/*
		Starting Chilik Controller
	*/
	
	Controller::Init()->start();
	
